package org.example.jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

public class PaDyGans {
    public static void main(String[] args) throws IOException {
        DolowndDian();
    }
    public static void DolowndDian() throws IOException {
        //https://www.dygangs.net/ys/20241019/55711.htm
        //https://www.dygangs.net/ys/20241019/55710.htm
        String attr="https://www.dygangs.net/ys/20241019/55711.htm";
        URL url=new URL(attr);
        Map<String,String> dianYin=new HashMap<>();
        Document doc = Jsoup.parse(url, 5000);
        if(doc.selectFirst(".title a")!=null){
            dianYin.put("name",doc.selectFirst(".title a").text());
        }
        if(doc.selectFirst("table.border1>tbody>tr>td img")!=null){
            dianYin.put("image",doc.selectFirst("table.border1>tbody>tr>td img").attr("src"));
        }
        if(doc.selectFirst("td:contains(发布时间: )")!=null){
            String releaseTime =doc.selectFirst("td:contains(发布时间：)").text();
            // 从文本中提取发布时间
            String[] releaseTimeParts = releaseTime.split("：");
            String extractedReleaseTime = releaseTimeParts[1].trim();
            dianYin.put("faTime",extractedReleaseTime);
        }
        System.out.println("dianYin="+dianYin);
    }
}
